#!/usr/bin/perl -wc

package RFCMail::PackIt::Type::Struct;

use strict;
use warnings;

use RFCMail::PackIt::Access;

# Object structure is ARRAY holding names of types in structure

sub define {
    my $class = shift;
    my $name = shift;
    my $self = [@_];
    bless $self, $class;
    register_type RFCMail::PackIt::Access $name, sub {$self->read(@_)}, sub {$self->write(@_)};
    return ($self);
}

sub read {
    my ($self, $access) = @_;
    my @struct;
    for (@$self) {
	push @struct, $access->read_type($_);
    }
    return (\@struct);
}

sub write {
    my $self = shift;
    my $access = shift;
    for (@_) {
	for (my $i = 0; $i < @$self; $i++) {
	    $access->write_type($self->[$i], $_->[$i]);
	}
    }
}

1;
